﻿
using AutoMapper;
using MediatR;
using MyMES.Domain.zmc;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.Incominginformations;

namespace MyMES.Writer.API.Application.CommendHandlers.Incominginformations
{
    public class DelIncominginformationsCommendHandlers : IRequestHandler<DelIncominginformationsCommends, APIResult<Incominginformation>>
    {
        private readonly IBaseRepository<Incominginformation> baseRepository;
        private readonly IMapper mapper;
     

        public DelIncominginformationsCommendHandlers(IBaseRepository<Incominginformation> baseRepository, IMapper mapper)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 删除--逻辑删
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<Incominginformation>> Handle(DelIncominginformationsCommends request, CancellationToken cancellationToken)
        {
            APIResult<Incominginformation> result = new APIResult<Incominginformation>();
            result.Code = APIEnum.删除成功;
            result.Msg = "删除成功";
            var list = mapper.Map<Incominginformation>(request);
            string sql = "update incominginformation set IsDlete=true where StorageId=@StorageId";
            await baseRepository.Update(list, sql);
            return result;
        }
    }
}
